﻿/*
 * @author: wizardc
 */

using System;
using Dou.Clip;
using UnityEngine;

namespace Demo.WorldMap
{
    /// <summary>
    /// GPU 渲染静态数据
    /// </summary>
    public class GPUStaticRenderData : ScriptableObject
    {
        public GPUStaticRenderTree[] trees;
    }

    // 因为GPU绘制在运行中，一颗树是完全独立存在并绘制的，所以导出时所有数据都塞树里面
    [Serializable]
    public class GPUStaticRenderTree
    {
        public string name;
        public GPUStaticRenderRes[] res;
        public GPUStaticRenderLODRes[] lodRes;
        public GPUStaticRenderNode[] nodes;
        public GPUStaticRenderLeaf[] leaves;
    }

    [Serializable]
    public class GPUStaticRenderRes
    {
        public int maxLod;
        public GPUStaticRenderLODInfo[] lod; // 每一层LOD的信息
        public Bounds bounds;
    }

    [Serializable]
    public class GPUStaticRenderLODInfo
    {
        public int[] lodId; // 指向 GPUStaticRenderTree.lod 的索引
    }
    
    [Serializable]
    public class GPUStaticRenderLODRes
    {
#if UNITY_EDITOR
        public Mesh mesh;
        public Material material;
#endif
        public string meshName;
        public string matName;
    }

    [Serializable]
    public struct GPUStaticRenderNode
    {
        public int index;
        public int child1;
        public int child2;
        public Bounds bounds;
        public int startLeafIndex;
        public int leafCount;
        public bool isLeaf => leafCount > 0;
        [NonSerialized]
        public FrustumClippingType clippingType; // 上次检测的结果
    }

    [Serializable]
    public struct GPUStaticRenderLeaf
    {
        public int resId;
        public int startDataIndex;
        public int dataCount;
        [NonSerialized]
        public int startBufferIndex; // 内存buffer数据中的开始索引
        [NonSerialized]
        public int bufferCount; // 内存buffer数据中的数量
        [NonSerialized]
        public bool newAdd; // 标记为本次新增的节点
    }
}
